home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Analysis / DSP (Fourier etc) / FTMagPhase < prev    next >
Text File  |  1994-06-03  |  3KB  |  85 lines

  1. #include <BringDestToFront>
  2. #include <Math Utility Functions>
  3.  
  4. | Given an input wave ( doesn't have to be a power of two), create a new wave
  5. | with the suffix "_Mag" that contains the normalized frequency response and
  6. | optionally a wave with the suffix "_Phase".
  7. | Several levels of resolution enhancement (really just sin x/x interpolation) are provided.
  8. | Options include windowing (Hann) vs no windowing, linear vs dB, phase vs no phase
  9. | If phase then option of radians or degrees,wrapped or unwrapped
  10. | You may want to modify the code at the end of this macro.  It sets the display
  11. | style and that is a matter of taste. To do this, you should make a copy of this
  12. | code and give it a different name. 
  13. |
  14. Macro FTMagPhase(w,window,resolution,linlog,phase,phasetype)
  15.     string w
  16.     Prompt w,"Input data:",popup WaveList("*",";","")
  17.     variable window=1
  18.     Prompt window,"Windowing:",popup "None;Hann"
  19.     variable resolution=1
  20.     Prompt resolution,"Resolution enhancement:",popup "none;2;4;8;16;32"
  21.     variable linlog= 2
  22.     Prompt linlog,"Magnitude mode:",popup "Linear;dB"
  23.     Variable phase= 1
  24.     Prompt phase,"Phase:",popup "No phase;Phase in radians;Phase in degrees"
  25.     Variable phasetype=1
  26.     Prompt phasetype,"Unwrap phase?",popup,"No;Yes"
  27. ;
  28.     PauseUpdate; silent 1
  29.     
  30.     string destw=w+"_Mag",phasew= w+"_Phase"
  31.     Variable n= numpnts($w)
  32.     
  33.     if( (resolution<1) %| (resolution>6) )
  34.         Abort "resolution out of range"
  35.     endif
  36.     resolution -= 1
  37.     Duplicate/O $w $destw
  38.     if(window==2)
  39.         Hanning $destw; $destw *= 2            | assumes continuous rather than pulsed data
  40.     endif
  41.     Redimension/N=(CeilPwr2(n)*2^resolution) $destw        | pad with zeros to power of 2
  42.     fft $destw
  43.     $destw= r2polar($destw)
  44.     | NOTE: depending on your application you may want to un-comment the next line
  45. |    $destw[0] /= 2                                | dc is special
  46.     if( phase!=1 )
  47.         Duplicate/O $destw $phasew
  48.         Redimension/R $phasew
  49.         $phasew= imag($destw)
  50.         if( phasetype==2 )
  51.             $phasew[0]= $phasew[1]            | try to avoid glitch at dc
  52.             UnWrap 2*Pi,$phasew
  53.             $phasew[0]= 0
  54.         endif
  55.         if(phase==3)
  56.             $phasew *= 180/Pi
  57.             SetScale y,0,0,"deg",$phasew
  58.         else
  59.             SetScale y,0,0,"rad",$phasew
  60.         endif
  61.     endif
  62.     Redimension/R $destw
  63.     if( linlog==2 )
  64.         WaveStats/Q $destw
  65.         $destw= 20*log($destw/V_max)
  66.         SetScale y,0,0,"dB",$destw
  67.     else
  68.         $destw /= n/2
  69.         SetScale y,0,0,"V",$destw
  70.     endif
  71.     BringDestFront(destw)
  72.     if( phase!=1 )
  73.         CheckDisplayed  $phasew
  74.         if( !V_Flag )
  75.             Append/R $phasew
  76.         endif
  77.     endif
  78.     if( numpnts($destw) <= 129 )
  79.         Modify mode($destw)=4,marker($destw)=19,msize($destw)=1
  80.     else
  81.         Modify mode($destw)=0
  82.     endif
  83. end
  84.  
  85.